<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Seourl extends CI_Controller {
    public $rear = '';
    function __construct() {
        parent::__construct();
        if($this->session->userdata('ngonngu') && $this->session->userdata('ngonngu')=='_en') {
            $this->rear = '_en';
            $this->lang->load('atta','english');
        }else{
            $this->lang->load('atta','vietnam');
        } 
    }

    function index() {
        $alias = preg_replace("/(.html)/", '', $this->security->xss_clean($this->uri->segment(1, 0)));
        if ($alias == 'tim-kiem') {
            $this->load->controller('mod_search/mod_search/index');
        } elseif ($alias == 'lien-he') {
            $this->load->controller('com_contact/com_contact/index');
        } else {
            // Lấy type của alias
            $a_id = $this->common_model->getone('alias', array('alias'.$this->rear => $alias));
            if (!empty($a_id)) {
                if ($a_id->type == 'danhmuctt') {
                    $this->load->controller('mod_tintuc/mod_tintuc/index', array('id' => $a_id->a_id, 'alias'.$this->rear => $alias));
                } elseif ($a_id->type == 'tintuc') {
                    $this->load->controller('mod_tintuc/mod_tintuc/detail',array('id' => $a_id->a_id, 'alias'.$this->rear => $alias));
                } elseif ($a_id->type == 'danhmucsp') {
                    $this->load->controller('mod_design/mod_design/getListProduct',array('id' => $a_id->a_id, 'alias'.$this->rear => $alias));
                } elseif ($a_id->type == 'sanpham'){
                    $this->load->controller('mod_design/mod_design/detail',array('id' => $a_id->a_id, 'alias'.$this->rear => $alias));
                } elseif ($a_id->type == '') {
                    $this->load->controller('mod_page/mod_page/index');
                } else {
                    $data['content'] = $this->load->view('404.php', '', true);
                    $this->load->view('template', $data);
                }
            } else {
                redirect(base_url());
            }
        }
    }

}
